{extend name="index/iframe" /}

{block name="content"}
<form class="layui-form layui-form-my" action="">
    <input type="hidden" name="id" value="{$Think.get.id}">
    <div class="layui-form-item">
        <label class="layui-form-label">活动标题</label>
        <div class="layui-input-block">
            <input type="text" value="{$find.title}" name="title" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">选择游戏</label>
        <div class="layui-input-block select-box">
            <select class="selectpicker" multiple data-live-search="true" data-style="btn-inverse" data-actions-box="true">
                {volist name="gameNotice" id="vo"}
                <option value="{$vo.game_id}" {in name="$vo.game_id" value="$find.game_id"}selected{else/}''{/in}>{$vo.game_id}:{$vo.game_name}</option>
                {/volist}
            </select>
            <input type="hidden" name="game_id" id="game_id" value="{$find.game_id}">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">使用范围</label>
        <div class="layui-input-block">
            <input type="text" value="{$find.server_id}" name="server_id" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">过期时间</label>
        <div class="layui-input-block">
            <input type="text" value="{$find.start_time} - {$find.end_time}" name="datetime" id="datetime" lay-verify="datetime" placeholder="yyyy-MM-dd HH:mm:ss - yyyy-MM-dd HH:mm:ss" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block" style="width: 700px;">
            <textarea id="content" name="content" style="display: none;">{$find.content}</textarea>
        </div>
    </div>
    <div class="layui-form-item" style="margin-bottom: 100px;">
        <div class="layui-input-block">
            <button class="layui-btn my-btn" lay-submit="" lay-filter="submitBtn">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
{/block}

{block name="css"}
<link rel="stylesheet" href="__STATIC__/js/bootselect/bootstrap-3.3.4.css">
<link rel="stylesheet" href="__STATIC__/js/bootselect/dist/css/bootstrap-select.css">
{/block}

{block name="js"}
<script src="__STATIC__/js/bootselect/jquery-2.0.3.min.js"></script>
<script src="__STATIC__/js/bootselect/bootstrap-3.3.4.js"></script>
<script src="__STATIC__/js/bootselect/dist/js/bootstrap-select.js"></script>
<script>
layui.use(['form', 'layedit', 'laydate', 'table'], function(){
    var form = layui.form
        ,$ = layui.$
        ,layer = layui.layer
        ,laydate = layui.laydate
        ,layedit = layui.layedit;

    //多选
    $('.selectpicker').change(function() {
        $('#game_id').val($(this).val());
    })
    $('.select-box .layui-form-select').css('display', 'none');

    //html编辑器
    layedit.set({
        uploadImage: {
            url: '{:url("Base/upload", "name=activity")}'
        }
    });
    var index = layedit.build('content', {height: 600});

    //日期
    laydate.render({
        elem: '#datetime'
        ,type: 'datetime'
        ,range: true
    });

//    //区服
//    getServer({$find['game_id']});
//    form.on('select(game_id)', function(data){
//        getServer(data.value);
//    });
//    function getServer(game_id){
//        var load = layer.load()
//            ,server_id = {$find['server_id']};
//        $.post('{:url("Base/getServer")}',{game_id:game_id,server_id:server_id}, function(json){
//            layer.close(load);
//            json.code==0 ? $('#server_id').html(json.data) : $('#server_id').html('<option value="">全服</option>');
//            form.render('select');
//        }, 'JSON');
//    }

    //提交
    form.on('submit(submitBtn)', function(data){
        data.field.content = layedit.getContent(index);
        var load = layer.load();
        $.post('{:url("Activity/edit")}',data.field, function(json){
            layer.close(load);
            json.code==0 ? layer.msg(json.msg, {icon: 1, time: 1000}) : layer.msg(json.msg, {icon: 0, time: 1000});
        }, 'JSON').error(function(){
            layer.close(load);
            layer.msg('连接超时，请联系后台管理员', {icon: 2, time:3000});
        });
        return false;
    });
});
</script>
{/block}